<?php
include 'method/win.php';
if(isset($_POST['submit'])){
    //     register($_POST['username'], md5($_POST['password']), $_POST['telephone']);
    if(preg_match("/^1[34578]{1}\d{9}$/",$_POST['telephone'])){
        register($_POST['username'], md5($_POST['password']), $_POST['telephone']);
    }else{
        show_msg("请输入有效手机号码进行注册", "register.php");
    }
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>小狗微博注册页面</title>
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/register.css">
    <script src="../lib/jquery/jquery.js"></script>
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">

</head>
<body class="gray-bg"  id="i88" style="margin: 0">
<script>
function check(){
	if(myform.username.value==""){
		alert("用户名不能为空!");
		return false;
	}
	if(myform.username.value.length < 2 || myform.username.value.length >10){
		alert("用户名长度应为2到10位");
		return false;
	}
	if(myform.password.value==""){
		alert("密码不能为空!");
		return false;
	}
	if(myform.password.value.length < 3 || myform.password.value.length >10){
		alert("密码长度应为3到10位");
		return false;
	}
	if(myform.telephone.value==""){
		alert("请输入注册电话号码!");
		return false;
	}
	if(document.getElementById("div1").innerHTML=="用户已经存在!"){
		alert("用户已经存在!");
		return false;
	}
	return true;
}

$(document).ready(function(){
	$("#username").blur(function(){
		var user = $(this).val();
		$.ajax({
			type:"post",
			url:"method/check_name.php",
// 			dataType:"json",
			data:{user:user},
			success:function(data){
				$("#div1").html(data);
			}
		});
	});
});
</script>
<div class="well col-md-4">
    <h3>用户注册</h3>
<form name="myform" method="post" onsubmit="return check()" action="" id="myform">
    <div class="left"></div>
    <div class="pg_body ">
        <div class="menu"><i class="glyphicon glyphicon-user"></i></div>
        <div class="kong">
            <input id="username" type="text" name="username" placeholder="请输入用户名">
                         <span id="div1" class="tian float-right">*(为必填)</span>
        </div>
        <div class="menu"><i class="glyphicon glyphicon-lock"></i></div>
        <div class="kong">
            <input id="password" type="password" name="password" placeholder="请输入密码"> <span id="div2" class="tian float-right">*(为必填)</span>

        </div>
        <div class="menu"><i class="glyphicon glyphicon-phone"></i></div>
        <div class="kong">
            <input id="telephone" type="text" name="telephone" placeholder="请输入电话号码"><span id="div3" class="tian float-right">*(为必填)</span>

        </div>
    </div>
    <div class="can">
        <input id="i111" type="submit" name="submit" value="注  册">
        <p style="width: 100px;display: inline-block;"></p>
        <a href="index.php"><input id="i222" type="button" name="004" value="取  消"></a>
        <a class="btn btn-sm btn-white btn-block" style="text-align: right;" href="login.php"><h6>已有账户？前往登录</h6></a>
    </div>
</form>
</div>

</body>

</html>